
import { defineStore } from "pinia";



export const useLowCodeStore: any = defineStore({
    id: "lowCode",
    state: (): any => {
        return {
            component: [
                {
                    code: "button",
                    set: "button-set",
                    name: "按钮",
                    id: 1, //组件编号不可重复且递增
                    props: {
                        type: "primary",
                    },
                },
                {
                    code: "input",
                    set: "input-set",
                    name: "输入框",
                    id: 2, //组件编号不可重复且递增
                    props: {
                        value: "",
                        placeholder: "请输入内容",
                    },
                }
            ],
            preview: [],
            nowComponent: {},
        }
    },
    actions: {
        previewData(value: any) {
            this.preview.push(value)
        },
        nowComponentsData(value: any) {
            this.nowComponent = value;
        },
        updateNowComponents(value:any) {
            this.nowComponent = value;
            const index = this.preview.findIndex((item:any) => item.id === value.id);
            this.preview[index] = value;
        },

    }
})

